#ifndef VRP_LIT_INPUT_INCLUDED
#define VRP_LIT_INPUT_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "../ShaderLib/VInput.hlsl"

CBUFFER_START(UnityLighting)

//主灯光方向
float4 _VMainLightDirection;
//主灯光颜色
half4 _VMainLightColor;

//主灯光 世界空间->投影空间变换矩阵
float4x4 _VMainLightMatrixWorldToShadowMap;

CBUFFER_END







TEXTURECUBE(IBL_irradianceMap);
TEXTURECUBE(IBL_lobeSpecularMap);
SAMPLER(my_Linear_clamp_sampler);
TEXTURE2D(IBL_BRDFMap);
TEXTURE2D(_DFGMultiScatteringLUT);
TEXTURE2D(MultiScattering_LUT_Avg);
SAMPLER(my_point_clamp_sampler);
float4 IBL_irradianceMap_TexelSize;
float4 IBL_lobeSpecularMap_TexelSize;
float4 IBL_BRDFMap_TexelSize;
float  IBL_Intensity;
struct VSurface
{
    float3 albedo;
    float alpha;
    float metallic;
    float smoothness;
    //float2 dfg;
    #ifdef _CLEARCOAT
    float clearCoat;
    float clearCoatPerceptualRoughness;
    float clearCoatRoughness;
    #endif

};
struct VDirectLighting
{
    float3 diffuseLighting;
    float3 specularLighting;
};
CBUFFER_START(UnityPerMaterial)
float4 _BaseMap_ST;
half4 _BaseColor;
half _Smoothness;
half _Metallic;
float _ClearCoat;
float _ClearCoatStrength;
float _ClearCoatRoughness;

CBUFFER_END
inline void InitializeStandardLitSurfaceData(float2 uv, out VSurface outSurfaceData)
{
   
    outSurfaceData.albedo = _BaseColor.rgb;
    outSurfaceData.alpha = _BaseColor.a;
    outSurfaceData.metallic = _Metallic;
    outSurfaceData.smoothness = _Smoothness;
    #ifdef _CLEARCOAT
    outSurfaceData.clearCoat=_ClearCoat;
    outSurfaceData.clearCoatPerceptualRoughness=_ClearCoatStrength;
    outSurfaceData.clearCoatRoughness=_ClearCoatRoughness;
    #endif
}

float2 GetDFG(float NoV, float perceptualRoughness)
{
    float2 uv = float2(lerp(0, 0.99, NoV), lerp(0, 0.99, perceptualRoughness));
    #if defined(_MULTISCATTERING)
    float2 dfg = SAMPLE_TEXTURE2D_LOD(_DFGMultiScatteringLUT, my_point_clamp_sampler, uv, 0.0).xy;
    #else
    float2 dfg = SAMPLE_TEXTURE2D_LOD(_DFGMultiScatteringLUT, my_point_clamp_sampler, uv, 0.0).xy;
    #endif

    return dfg;
}

float2 GetDFG(VInputData surface,float perceptualRoughness)
{
    return GetDFG(dot(surface.normalWS, surface.viewDirectionWS), perceptualRoughness);
}
float3 Get_Eu(float cos_term,float perceptualRoughness)
{
    float2 uv = float2(lerp(0, 0.99, cos_term), lerp(0, 0.99, perceptualRoughness));
    float3 dfg = SAMPLE_TEXTURE2D_LOD(_DFGMultiScatteringLUT, my_point_clamp_sampler, uv, 0.0).xyz;
    return dfg;
}
float3 Get_Eavg(float perceptualRoughness)
{
    float2 uv = float2(0, lerp(0, 0.99, perceptualRoughness));
    float3 dfg = SAMPLE_TEXTURE2D_LOD(MultiScattering_LUT_Avg, my_point_clamp_sampler, uv, 0.0).xyz;
    return dfg;
}
#endif